package com.flute.haflute.jobbox.communication;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import com.flute.haflute.jobbox.communication.messages.MessageBase;
import com.flute.haflute.jobbox.master.NotifyServiceManager;

/**
 * 通信平台消息发送器接口
 * 
 * 子节点向该接口注册，该接口将注册的子节点注入后台通知线程 具体通知由后台消息通知器NotifyDaemon完成
 * 
 * 该接口隔离了具体通知器/监听器的具体实现
 */
public class Notifier extends UnicastRemoteObject implements NotifyService {
	
	private static final long serialVersionUID = 5898963670584678829L;

	protected Notifier() throws RemoteException {
		super();
		NotifyServiceManager.add2ServiceCache(this);
	}

	@Override
	public void close() throws Exception {
		// TODO
	}

	@Override
	public void register(String name, Listener callback) throws RemoteException {
		NotifiyDaemon.getInstance().register(name, callback);
	}

	@Override
	public void send(String topic, MessageBase request) throws RemoteException {
		NotifiyDaemon.getInstance().send(topic, request);
	}

	@Override
	public void unRegister(String name) throws RemoteException {
		NotifiyDaemon.getInstance().unRegister(name);

	}

	@Override
	public void broadcast(MessageBase request) throws RemoteException {
		NotifiyDaemon.getInstance().broadcast(request);
	}

	@Override
	public boolean isAlive() throws RemoteException {
		return true;
	}

}
